package cn.dengta.webapp.user.entity;

import java.io.Serializable;

import cn.dengta.common.model.Status;
import cn.dengta.context.model.WesKit;
import cn.dengta.webapp.user.model.Gender;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.X;

/**
 * 个性化配置对象
 */
@Getter
@Setter
@Accessors(chain = true)
public class SwitchConfig implements Serializable {

	private static final long serialVersionUID = 1L;
	//
	/** 电视墙礼物匿名 */
	protected Integer tvAnonymous;
	/** 礼物匿名 */
	protected Integer giftAnonymous;

	public void validate(SwitchConfig input) {
		X.use(input.tvAnonymous, v -> this.setTvAnonymous(Status.valueOf(v)));
		X.use(input.giftAnonymous, v -> this.setGiftAnonymous(Status.valueOf(v)));
	}

	public static SwitchConfig init(WesKit wesKit, Gender gender) {
		Status status = Status.NO;
		if (wesKit.isInterior() && gender == Gender.FEMALE) {
			status = Status.YES;
		}
		SwitchConfig cfg = new SwitchConfig();
		cfg.tvAnonymous = status.value;
		cfg.giftAnonymous = status.value;
		return cfg;
	}

	public SwitchConfig init(SwitchConfig input) {
		this.tvAnonymous = X.expectNotNull(input.tvAnonymous, tvAnonymous, Status.NO.value);
		this.giftAnonymous = X.expectNotNull(input.giftAnonymous, giftAnonymous, Status.NO.value);
		return this;
	}

	public boolean tvAnonymousOpen() {
		return Status.asResult(tvAnonymous);
	}

	public boolean giftAnonymousOpen() {
		return Status.asResult(giftAnonymous);
	}

}
